package demo1;

public class Test {
    public static void main(String[] args) {
        StringBuilder stringBuilder = new StringBuilder("abc");
        System.out.println(stringBuilder);

        //拼接
        stringBuilder.append("abg").append("sdf");
        stringBuilder.append(324.6);
        System.out.println(stringBuilder);


        stringBuilder.reverse();//逆置
        System.out.println(stringBuilder);

        String str = stringBuilder.toString();
        System.out.println(stringBuilder.toString());
        System.out.println("==============");
    }
    public static void main11(String[] args) {

        String str = "    hello  world   ";
        String s1 = str.trim();
        System.out.println(s1);//hello  world    只会删除两边的空格

    }
    public static void main10(String[] args) {
        String str = "abcdefg";
        //截取字符串
        String s = str.substring(2);
        System.out.println(s);//cdefg

        String s1 = str.substring(2,5);
        System.out.println(s1);//cde  [)


    }
    public static void main9(String[] args) {
        String str1 = "192&168|20&55";
        String[] strs = str1.split("&|=|\\|");
        for (int i = 0; i < strs.length; i++) {
            System.out.print(strs[i] + " ");//192 168 20 55
        }
    }
    public static void main8(String[] args) {
        String str1 = "192.168.20.55";
        String[] strs = str1.split("\\.");
        for (int i = 0; i < strs.length; i++) {
            System.out.print(strs[i] + " ");        //192 168 20 55
        }
        System.out.println();
        String str2 = "192\\168\\20\\55";
        String[] strs1 = str2.split("\\\\");
        for (int i = 0; i < strs1.length; i++) {
            System.out.print(strs1[i] + " ");       //192 168 20 55
        }

    }
    public static void main7(String[] args) {
        String str1 = "hello world Java";
        String[] strs = str1.split(" ",2);
        for (int i = 0; i < strs.length; i++) {
            System.out.println(strs[i]);
        }
    }
    public static void main6(String[] args) {
        String str1 = "asdfgfgfhs";
        String ret1 = str1.replace('g','w');  //asdfwfwfhs
        System.out.println(ret1);

        String ret2 = str1.replace("fg","pq");  //asdpqpqfhs
        System.out.println(ret2);

        String ret3 = str1.replaceAll("fg","oo");
        System.out.println(ret3);//asdoooofhs

        String ret4 = str1.replaceFirst("fg","oo"); //传入字符串
        System.out.println(ret4);//asdoofgfhs


    }
    public static void main5(String[] args) {
        String str1 = "asdfasd";
        char[] array = str1.toCharArray();//字符串转数组

    }

    public static void main4(String[] args) {
        String str1 = "abcdf";
        String str2 = "ABFDSF";
        System.out.println(str1.toUpperCase());//ABCDF
        System.out.println(str2.toLowerCase());//abfdsf
    }

    public static void main3(String[] args) {
        String str2 = String.valueOf(123445);
        System.out.println(str2);

        //字符串转数字
        String str1 = "1234";
        int data = Integer.parseInt(str1);
        System.out.println(data);//1234
        double data2 = Double.parseDouble(str1);
        System.out.println(data2);//1234.0

    }
    public static void main2(String[] args) {
        String str1 = "helloeee";
        char ch = str1.charAt(1);
        System.out.println(ch);  //e

        System.out.println(str1.indexOf('e',4));  //找e  从指定位置(4)开始
        System.out.println(str1.indexOf("lloe")); //2
        System.out.println(str1.lastIndexOf('e'));//从后往前找
        System.out.println(str1.lastIndexOf('e',5));//从5下标(包括5下标)后往前找

        for (int i = 0; i < str1.length(); i++) {
            System.out.print(str1.charAt(i) + " ");
        }
    }
    public static void main1(String[] args) {
        char[] values = {'a','b','c','d','e'};

        String s1 = new String(values);
        System.out.println(s1);
        System.out.println(s1.length());
        System.out.println("abcdefg".length());

        String str1 = new String("hello");
        String str2 = new String("hello");
        //str1 和 str2  进行比较
        System.out.println(str1.compareTo(str2));
        //忽略大小写进行比较
        System.out.println(str1.compareToIgnoreCase(str2));
        //忽略大小写进行比较  是否相当
        System.out.println(str1.equalsIgnoreCase(str2));


    }
}
